<!-- HTML header for doxygen 1.8.6-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<title>OpenCV: G-API Drawing and composition functionality</title>
<link href="../../opencv.ico" rel="shortcut icon" type="image/x-icon" />
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../jquery.js"></script>
<script type="text/javascript" src="../../dynsections.js"></script>
<script type="text/javascript" src="../../tutorial-utils.js"></script>
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../search/searchdata.js"></script>
<script type="text/javascript" src="../../search/search.js"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
    jax: ["input/TeX","output/HTML-CSS"],
});
//<![CDATA[
MathJax.Hub.Config(
{
  TeX: {
      Macros: {
          matTT: [ "\\[ \\left|\\begin{array}{ccc} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{array}\\right| \\]", 9],
          fork: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ \\end{array} \\right.", 4],
          forkthree: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ \\end{array} \\right.", 6],
          forkfour: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ #7 & \\mbox{#8}\\\\ \\end{array} \\right.", 8],
          vecthree: ["\\begin{bmatrix} #1\\\\ #2\\\\ #3 \\end{bmatrix}", 3],
          vecthreethree: ["\\begin{bmatrix} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{bmatrix}", 9],
          cameramatrix: ["#1 = \\begin{bmatrix} f_x & 0 & c_x\\\\ 0 & f_y & c_y\\\\ 0 & 0 & 1 \\end{bmatrix}", 1],
          distcoeffs: ["(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \\tau_x, \\tau_y]]]]) \\text{ of 4, 5, 8, 12 or 14 elements}"],
          distcoeffsfisheye: ["(k_1, k_2, k_3, k_4)"],
          hdotsfor: ["\\dots", 1],
          mathbbm: ["\\mathbb{#1}", 1],
          bordermatrix: ["\\matrix{#1}", 1]
      }
  }
}
);
//]]>
</script><script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js"></script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
<link href="../../stylesheet.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<!--#include virtual="/google-search.html"-->
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="../../opencv-logo-small.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">OpenCV
   &#160;<span id="projectnumber">4.5.2</span>
   </div>
   <div id="projectbrief">Open Source Computer Vision</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "../../search",false,'Search');
</script>
<script type="text/javascript" src="../../menudata.js"></script>
<script type="text/javascript" src="../../menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('../../',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="summary">
<a href="#groups">Modules</a>  </div>
  <div class="headertitle">
<div class="title">G-API Drawing and composition functionality</div>  </div>
</div><!--header-->
<div class="contents">

<p>Functions for in-graph drawing.  
<a href="#details">More...</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="groups"></a>
Modules</h2></td></tr>
<tr class="memitem:de/db8/group__gapi__draw__prims"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../de/db8/group__gapi__draw__prims.html">Drawing primitives</a></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:d0/d43/group__gapi__draw__api"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d0/d43/group__gapi__draw__api.html">Drawing operations and functions</a></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<p>Functions for in-graph drawing. </p>
<dl class="section note"><dt>Note</dt><dd>This is a Work in Progress functionality and APIs may change in the future releases.</dd></dl>
<p>G-API can do some in-graph drawing with a generic operations and a set of <a class="el" href="../../de/db8/group__gapi__draw__prims.html">rendering primitives</a>. In contrast with traditional OpenCV, in G-API user need to form a <em>rendering list</em> of primitives to draw. This list can be built manually or generated within a graph. This list is passed to <a class="el" href="../../d0/d43/group__gapi__draw__api.html">special operations or functions</a> where all primitives are interpreted and applied to the image.</p>
<p>For example, in a complex pipeline a list of detected objects can be translated in-graph to a list of <a class="el" href="../../d6/d30/structcv_1_1gapi_1_1wip_1_1draw_1_1Rect.html" title="This structure represents a rectangle to draw. ">cv::gapi::wip::draw::Rect</a> primitives to highlight those with bounding boxes, or a list of detected faces can be translated in-graph to a list of <a class="el" href="../../d0/d07/structcv_1_1gapi_1_1wip_1_1draw_1_1Mosaic.html" title="This structure represents a mosaicing operation. ">cv::gapi::wip::draw::Mosaic</a> primitives to hide sensitive content or protect privacy.</p>
<p>Like any other operations, rendering in G-API can be reimplemented by different backends. Currently only an OpenCV-based backend is available.</p>
<p>In addition to the graph-level operations, there are also regular (immediate) OpenCV-like functions are available &ndash; see <a class="el" href="../../d0/d43/group__gapi__draw__api.html#gaa315ba452961559eb9222d3ace8ce178" title="The function renders on the input image passed drawing primitivies. ">cv::gapi::wip::draw::render()</a>. These functions are just wrappers over regular G-API and build the rendering graphs on the fly, so take compilation arguments as parameters.</p>
<p>Currently this API is more machine-oriented than human-oriented. The main purpose is to translate a set of domain-specific objects to a list of primitives to draw. For example, in order to generate a picture like this:</p>
<div class="image">
<img src="../../render_example.png" alt="render_example.png"/>
</div>
<p>Rendering list needs to be generated as follows:</p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="../../d1/d4f/imgproc_2include_2opencv2_2imgproc_8hpp.html">opencv2/imgproc.hpp</a>&gt;</span> <span class="comment">// cv::FONT*, cv::LINE*, cv::FILLED</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="../../d4/dd5/highgui_8hpp.html">opencv2/highgui.hpp</a>&gt;</span> <span class="comment">// imwrite</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="../../d7/d20/gapi_8hpp.html">opencv2/gapi.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="../../d6/d4b/render_8hpp.html">opencv2/gapi/render.hpp</a>&gt;</span></div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[])</div><div class="line">{</div><div class="line">    <span class="keywordflow">if</span> (argc &lt; 2) {</div><div class="line">        std::cerr &lt;&lt; <span class="stringliteral">&quot;Filename required&quot;</span> &lt;&lt; std::endl;</div><div class="line">        <span class="keywordflow">return</span> 1;</div><div class="line">    }</div><div class="line"></div><div class="line">    <span class="keyword">const</span> <span class="keyword">auto</span> font  = <a class="code" href="../../d6/d6e/group__imgproc__draw.html#gga0f9314ea6e35f99bb23f29567fc16e11ab307bdc73fdd06074acad940115bda7a">cv::FONT_HERSHEY_DUPLEX</a>;</div><div class="line">    <span class="keyword">const</span> <span class="keyword">auto</span> blue  = <a class="code" href="../../d1/da0/classcv_1_1Scalar__.html">cv::Scalar</a>{ 255,   0,   0}; <span class="comment">// B/G/R</span></div><div class="line">    <span class="keyword">const</span> <span class="keyword">auto</span> green = <a class="code" href="../../d1/da0/classcv_1_1Scalar__.html">cv::Scalar</a>{   0, 255,   0};</div><div class="line">    <span class="keyword">const</span> <span class="keyword">auto</span> coral = <a class="code" href="../../d1/da0/classcv_1_1Scalar__.html">cv::Scalar</a>{0x81,0x81,0xF1};</div><div class="line">    <span class="keyword">const</span> <span class="keyword">auto</span> white = <a class="code" href="../../d1/da0/classcv_1_1Scalar__.html">cv::Scalar</a>{ 255, 255, 255};</div><div class="line">    <a class="code" href="../../d3/d63/classcv_1_1Mat.html">cv::Mat</a> test(<a class="code" href="../../d6/d50/classcv_1_1Size__.html">cv::Size</a>(480, 160), <a class="code" href="../../d1/d1b/group__core__hal__interface.html#ga88c4cd9de76f678f33928ef1e3f96047">CV_8UC3</a>, white);</div><div class="line"></div><div class="line">    <span class="keyword">namespace </span>draw = <a class="code" href="../../df/d8d/namespacecv_1_1gapi_1_1wip_1_1draw.html">cv::gapi::wip::draw</a>;</div><div class="line">    std::vector&lt;draw::Prim&gt; prims;</div><div class="line">    prims.emplace_back(draw::Circle{   <span class="comment">// CIRCLE primitive</span></div><div class="line">            {400,72},                  <span class="comment">// Position (a cv::Point)</span></div><div class="line">            32,                        <span class="comment">// Radius</span></div><div class="line">            coral,                     <span class="comment">// Color</span></div><div class="line">            <a class="code" href="../../d6/d6e/group__imgproc__draw.html#ggaf076ef45de481ac96e0ab3dc2c29a777a89c5f6beef080e6df347167f85e07b9e">cv::FILLED</a>,                <span class="comment">// Thickness/fill type</span></div><div class="line">            <a class="code" href="../../d6/d6e/group__imgproc__draw.html#ggaf076ef45de481ac96e0ab3dc2c29a777a5d32eda7017db273a37f158e5b51442a">cv::LINE_8</a>,                <span class="comment">// Line type</span></div><div class="line">            0                          <span class="comment">// Shift</span></div><div class="line">        });</div><div class="line">    prims.emplace_back(draw::Text{     <span class="comment">// TEXT primitive</span></div><div class="line">            <span class="stringliteral">&quot;Hello from G-API!&quot;</span>,       <span class="comment">// Text</span></div><div class="line">            {64,96},                   <span class="comment">// Position (a cv::Point)</span></div><div class="line">            font,                      <span class="comment">// Font</span></div><div class="line">            1.0,                       <span class="comment">// Scale (size)</span></div><div class="line">            blue,                      <span class="comment">// Color</span></div><div class="line">            2,                         <span class="comment">// Thickness</span></div><div class="line">            <a class="code" href="../../d6/d6e/group__imgproc__draw.html#ggaf076ef45de481ac96e0ab3dc2c29a777a5d32eda7017db273a37f158e5b51442a">cv::LINE_8</a>,                <span class="comment">// Line type</span></div><div class="line">            <span class="keyword">false</span>                      <span class="comment">// Bottom left origin flag</span></div><div class="line">        });</div><div class="line">    prims.emplace_back(<a class="code" href="../../dc/d84/group__core__basic.html#ga11d95de507098e90bad732b9345402e8">draw::Rect</a>{     <span class="comment">// RECTANGLE primitive</span></div><div class="line">            {16,48,400,72},            <span class="comment">// Geometry (a cv::Rect)</span></div><div class="line">            green,                     <span class="comment">// Color</span></div><div class="line">            2,                         <span class="comment">// Thickness</span></div><div class="line">            <a class="code" href="../../d6/d6e/group__imgproc__draw.html#ggaf076ef45de481ac96e0ab3dc2c29a777a5d32eda7017db273a37f158e5b51442a">cv::LINE_8</a>,                <span class="comment">// Line type</span></div><div class="line">            0                          <span class="comment">// Shift</span></div><div class="line">        });</div><div class="line">    prims.emplace_back(draw::Mosaic{   <span class="comment">// MOSAIC primitive</span></div><div class="line">            {320,96,128,32},           <span class="comment">// Geometry (a cv::Rect)</span></div><div class="line">            16,                        <span class="comment">// Cell size</span></div><div class="line">            0                          <span class="comment">// Decimation</span></div><div class="line">        });</div><div class="line">    <a class="code" href="../../d2/d3c/group__core__opengl.html#ga64c7a6323ba1b978f2f9142a4bad5ca1">draw::render</a>(test, prims);</div><div class="line">    <a class="code" href="../../d4/da8/group__imgcodecs.html#gabbc7ef1aa2edfaa87772f1202d67e0ce">cv::imwrite</a>(argv[1], test);</div><div class="line">    <span class="keywordflow">return</span> 0;</div><div class="line">}</div></div><!-- fragment --> </div><!-- contents -->
<!-- HTML footer for doxygen 1.8.6-->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Fri Apr 2 2021 11:36:41 for OpenCV by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="../../doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
<script type="text/javascript">
//<![CDATA[
addTutorialsButtons();
//]]>
</script>
</body>
</html>
